<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取按指定宽度截断的字符串</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.mb-strimwidth" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mb_strimwidth</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.6, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">mb_strimwidth</span> &mdash; <span class="dc-title">获取按指定宽度截断的字符串</span></p>

 </div>
   
 <div class="refsect1 description" id="refsect1-function.mb-strimwidth-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mb_strimwidth</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$str</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$start</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$width</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$trimmarker</code><span class="initializer"> = &quot;&quot;</span></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$encoding</code><span class="initializer"> = mb_internal_encoding()</span></span>
  ]] ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   按 <code class="parameter">width</code> 将<span class="type"><span class="type 字符串">字符串</span></span> <code class="parameter">str</code> 截短。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mb-strimwidth-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">str</code></dt>

     <dd>

      <p class="para">
       要截短的 <span class="type"><a href="language.types.string.html" class="type string">string</a></span>。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">start</code></dt>

     <dd>

      <p class="para">
       开始位置的偏移。从这些字符数开始的截取字符串。（默认是 0 个字符）
       如果 start 是负数，就是字符串结尾处的字符数。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">width</code></dt>

     <dd>

      <p class="para">
       所需修剪的宽度。负数的宽度是从字符串结尾处统计的。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">trimmarker</code></dt>

     <dd>

      <p class="para">
       当字符串被截短的时候，将此字符串添加到截短后的末尾。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">encoding</code></dt>

     <dd>

      <p class="para"><code class="parameter">encoding</code>
参数为字符编码。如果省略，则使用内部字符编码。</p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mb-strimwidth-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   截短后的 <span class="type"><a href="language.types.string.html" class="type string">string</a></span>。
   如果设置了 <code class="parameter">trimmarker</code>，还将结尾处的字符替换为 <code class="parameter">trimmarker</code> ，并符合 <code class="parameter">width</code> 的宽度。
  </p>
 </div>

 
<div class="refsect1 changelog" id="refsect1-function.mb-strimwidth-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>7.1.0</td>
      <td>
       支持负数的 <code class="parameter">start</code> 和 <code class="parameter">width</code>。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>

 
 <div class="refsect1 examples" id="refsect1-function.mb-strimwidth-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3192">
    <p><strong>Example #1 <span class="function"><strong>mb_strimwidth()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">mb_strimwidth</span><span style="color: #007700">(</span><span style="color: #DD0000">"Hello&nbsp;World"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"..."</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;输出&nbsp;Hello&nbsp;W...<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mb-strimwidth-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="mb_strwidth.html" class="function" rel="rdfs-seeAlso">mb_strwidth()</a> - 返回字符串的宽度</span></li>
    <li class="member"><span class="function"><a href="mb_internal_encoding.html" class="function" rel="rdfs-seeAlso">mb_internal_encoding()</a> - 设置/获取内部字符编码</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>